package com.sooncode.project.focusservice._.request;

import com.sooncode.project.focusservice._.exceptions.RequestHttpErrorException;
import com.sooncode.project.springcloudcommon.config.MyFeignConfig;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@FeignClient(value = "usercenter-service",fallbackFactory = UserClient.userclientFallback.class,configuration = MyFeignConfig.class)
public interface UserClient {
    @GetMapping(value = "/user/publicApi/isExistByUserName")
    boolean checkUserExist(@RequestParam("userName") String userName);
    @PostMapping(value="/user/publicApi/user")
    String addNewUser(@RequestParam("userName") String userName,
                      @RequestParam("realName") String realName,
                      @RequestParam("userType") String userType
    );
    @DeleteMapping(value="/user/user")
    boolean deleteUser(@RequestParam("id") String id);
    @GetMapping(value = "/user/userByUsername")
    Map getUser(@RequestParam("userName") String userName);
    @PutMapping(value = "/user/password")
    boolean modifyPassword(@RequestParam("id") String id,@RequestParam("oldPassword") String oldPassword,@RequestParam("newPassword") String newPassword);
    @PostMapping(value = "/login/publicApi/index")
    Map login(@RequestParam("userName") String userName,@RequestParam("password") String password);
    @PostMapping(value = "/login/publicApi/loginById")
    Map loginById(@RequestParam("id") String id);
    @Component
    public class userclientFallback implements FallbackFactory<UserClient>{
        @Override
        public UserClient create(Throwable throwable) {
            throwable.printStackTrace();
            throw new RequestHttpErrorException(throwable.getMessage());
        }
    }
}
